//
//  LandmarkList.swift
//  ChinaLandmark
//
//  Created by iGhibli on 2020/12/17.
//

import SwiftUI

struct LandmarkList: View {
    
    @State private var showFavoritesOnly = false
    @EnvironmentObject var userData: UserData
    
    var body: some View {
        NavigationView {
            List {
                Toggle(isOn: $showFavoritesOnly) {
                    Text("只展示收藏")
                }
                ForEach(userData.userLandmarks) { landmark in
                    if !self.showFavoritesOnly || landmark.isFavorite {
                        NavigationLink(destination: LandmarkDetail(landmark: landmark).environmentObject(self.userData)) {
                            LandmarkCell(landmark: landmark)
                        }
                    }
                }
            }
            .navigationBarTitle(Text("中国地标"))
        }
    }
}

struct LandmarkList_Previews: PreviewProvider {
    static var previews: some View {
//        Group {
//            LandmarkList()
//                .previewDevice(PreviewDevice(rawValue: "iPhone12 mini"))
//                .previewDisplayName("iPhone12 mini")
//            LandmarkList()
//                .previewDevice(PreviewDevice(rawValue: "iPhone 7"))
//                .previewDisplayName("iPhone7")
//        }
        ForEach(["iPhone12 mini", "iPhone 7"], id: \.self) { deviceName in
            LandmarkList()
                .previewDevice(PreviewDevice(rawValue: deviceName))
                .previewDisplayName(deviceName)
        }
        .environmentObject(UserData())
    }
}
